package com.ftar.urgent.util;

import android.content.Context;

import com.ftar.urgent.model.RootCatalogModel;
import com.google.gson.Gson;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: wei.jin
 * @date: 2023/7/5
 * @email: wei.jin@fanttec.com
 * @description：
 */
public class GetCatalog {

    public static List<RootCatalogModel.catalog> getCatalog(Context context) {
        List<RootCatalogModel.catalog> list = new ArrayList<>();

        //If sdcard path has catalog_config.json, use sdcard path


        //Use assert config
        try {
            InputStream is = context.getAssets().open("catalog_config.json");
            int lenght = is.available();
            byte[] buffer = new byte[lenght];
            is.read(buffer);
            String result = new String(buffer, "utf8");

            Gson gson = new Gson();
            RootCatalogModel rootCatalogModel = gson.fromJson(result, RootCatalogModel.class);
            list = rootCatalogModel.getRoot_catalog();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        return list;
    }
}
